package com.sh.data.engine.web.openapi.controller.workspace;

import com.sh.data.engine.application.model.dto.base.PagerResponse;
import com.sh.data.engine.application.model.dto.workspace.BaseProjectDTO;
import com.sh.data.engine.application.model.dto.workspace.ProjectDTO;
import com.sh.data.engine.application.model.request.management.UserProjectSaveRequest;
import com.sh.data.engine.application.service.management.ProjectUserApplicationService;
import com.sh.data.engine.web.webapi.controller.base.response.RestResponseEntity;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 工作空间
 *
 * @author: mengzheng.mhc
 * @date: 2024/11/15 11:22
 */
@Validated
@RestController
@RequestMapping("/openapi/project")
@Tag(name = "工作空间", description = "工作空间相关接口")
public class WorkspaceController {

    @Autowired
    private ProjectUserApplicationService projectUserApplicationService;

    @GetMapping("/list")
    @Operation(summary = "获取工作空间列表", description = "该接口用于查询用户的工作空间列表")
    public RestResponseEntity<PagerResponse<BaseProjectDTO>> listProjects(
        @Parameter(description = "分页页码", schema = @Schema(defaultValue = "1", minimum = "1"))
        @RequestParam(required = false, defaultValue = "1") Integer pageNum,
        @Parameter(description = "分页大小", schema = @Schema(defaultValue = "10", minimum = "1"))
        @RequestParam(required = false, defaultValue = "10") Integer pageSize
    ) {
        var result = projectUserApplicationService.getProjectList(pageNum, pageSize);
        return RestResponseEntity.success(result);
    }

    @GetMapping("/get")
    @Operation(summary = "获取工作空间详情", description = "该接口用于查询工作空间详情")
    public RestResponseEntity<ProjectDTO> getProject(
        @Parameter(description = "工作空间ID", required = true)
        @RequestParam Long projectId
    ) {
        var result = projectUserApplicationService.getProject(projectId);
        return RestResponseEntity.success(result);
    }

    @PostMapping("/add")
    @Operation(summary = "创建工作空间", description = "该接口用于创建工作空间")
    public RestResponseEntity<String> addProject(@RequestBody @Validated UserProjectSaveRequest param) {
        var result = projectUserApplicationService.addProject(param);
        return RestResponseEntity.success(result);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除工作空间", description = "该接口用于删除工作空间")
    public RestResponseEntity<String> deleteProject(
        @Parameter(description = "工作空间ID", required = true)
        @RequestParam Long projectId
    ) {
        var result = projectUserApplicationService.deleteProject(projectId);
        return RestResponseEntity.success(result);
    }
}
